package com.example.springboot_test.easyexcel.model.common;

import com.example.springboot_test.easyexcel.model.builder.common.BorderModelBuilder;
import lombok.Getter;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFColor;

/**
 * 边框信息
 *
 * @author xudongmaster
 */
@Getter
public class BorderModel {

    /**
     * 边框线条类型
     */
    private final BorderStyle borderStyle;
    /**
     * 边框线条颜色
     */
    private final Object borderColor;

    public BorderModel(BorderModelBuilder builder) {
        this.borderStyle = builder.getBorderStyle();
        this.borderColor = builder.getBorderColor();
    }

    /**
     * 创建边框信息
     *
     * @param borderStyle 边框线条类型
     * @param borderColor 边框线条颜色
     * @return 边框信息
     */
    public static BorderModel createBorderModel( BorderStyle borderStyle, Object borderColor) {
        return new BorderModelBuilder()
                //边框线条类型
                .borderStyle(borderStyle)
                //边框线条颜色
                .borderColor(borderColor != null && (!(borderColor instanceof IndexedColors) && !(borderColor instanceof XSSFColor))
                        ? null : borderColor)
                .build();
    }
}
